package com.matrix.order.domain.model;

import com.matrix.common.exception.BusinessException;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * @author 有点甜
 * @since 2025/7/27
 */
@Data
public class OrderItem implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    private Long id;

    private Long orderId;
    private Long productId;
    private String productName;
    private String productImageUrl;
    private String specs;
    private BigDecimal price;
    private Integer quantity;
    private Boolean added;
    private Integer status;
    private Long paymentId;

    public OrderItem() {}

    public void markForCancellation() {
        if (this.status != 0) {
            throw new BusinessException("该菜品当前状态无法申请退菜");
        }
        this.status = 1;
    }

    public void approveCancellation() {
        if (this.status != 1) {
            throw new BusinessException("该菜品未申请退菜或状态不正确");
        }
        this.status = 2;
    }

    public void rejectCancellation() {
        if (this.status != 1) {
            throw new BusinessException("该菜品未申请退菜或状态不正确");
        }
        this.status = 0;
    }
}